import java.util.ArrayList;

/**
 * ArrayList元素搜索
 */
public class ArrayListDemo6 {
    public static void main(String[] args) {
        Student s1 = new Student("20180302","叶孤城",23,"护理一班");
        Student s2 = new Student("20180303","东方不败",23,"推拿二班");
        Student s3 = new Student("20180304","西门吹雪",26,"中药学一班");
        Student s4 = new Student("20180305","梅超风",27,"法律一班");
        ArrayList<Student> list = new ArrayList<>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        System.out.println("遍历");
        trans(list);
        System.out.println("搜索");
        search(list,"20180306");

    }
    public  static void trans(ArrayList<Student> list){
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            System.out.println(student.getNumber() +" "+ student.getName()+" "+student.getClassName());
        }
    }
    public  static void search(ArrayList<Student> list,String number){
        boolean flag = false;
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            if (student.getNumber().equals(number)){
                flag = true;
                System.out.println(student.getNumber() +" "+ student.getName()+" "+student.getClassName());
            }
        }
        if(!flag){
            System.out.println("没有此人");
        }

    }
}



class Student{
    private String number;
    private String name;
    private int age;
    private String className;

    public Student(String number, String name, int age, String className) {
        this.number = number;
        this.name = name;
        this.age = age;
        this.className = className;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }


}